
package com.zsrt.day20170418.ch03;

import java.util.Random;
import java.util.Scanner;

import org.junit.Test;

import com.zsrt.utils.ArrayUtil;


public class RandomTest {
	
	/**
	 * 发红包随机  后面顶多两位小数
	 * @throws Exception
	 */
	@Test
	public void test01() throws Exception {
		Random random = new Random();
		Scanner in = new Scanner(System.in);
		System.err.println("输入红包金额：");
		double total = in.nextInt();
		System.err.println("输入需要发的红包个数：");
		int num = in.nextInt();
		for (int i = 0; i < num - 1; i++) {
			int temp = (int)total * 100;
			int gift = (int)(random.nextDouble() * temp);
			System.err.println(gift/100.0);
			total = total - gift/100.0;
			//System.err.println("shengyu"+ total);
		}
		System.err.println(total);

		in.close();
		
	}
	
	/**
	 * 发红包随机
	 * @throws Exception
	 */
	@Test
	public void test03() throws Exception {
		Random random = new Random();
		Scanner in = new Scanner(System.in);
		System.err.println("输入红包金额：");
		int  total = in.nextInt();
		System.err.println("输入需要发的红包个数：");
		int num = in.nextInt();
		
		int sum=0;
		
		double n =0;
		for(int i=1;i<num;i++){
			sum+=n;
			double x =random.nextDouble();
			n = (total-sum)*x;
			System.out.println(n);
		}

		System.out.println((double)(total-sum));
		in.close();
	}
	
	
	
	/**
	 * 随机发牌求底牌
	 */
	@Test
	public void test02() throws Exception {
		
		String[] b = new String[]{"黑","红","方","梅"};
		int[] a = new int[13];
		
		Random random= new Random();
		
		
		int count = 0;
		String[] c = new String[54];
		for(int index =0;index<b.length;index++){
			
			for(int n = 0;n<a.length;n++){
				if(n == 0){
					c[count] = b[index] +"K";
				}else if(n ==11){
					
					c[count] = b[index] +"J";
				}else if(n==12){
					
						c[count] = b[index] +"Q";
				}else {
					
					c[count] = b[index]+n;
				}
			
				count++;	
			}	
		}
		c[52] = "小王";
		c[53] = "大王";
		//得出一副扑克
		ArrayUtil.StudentEntity(c);
		
		//得到要删除的数组
		int[] delete = new int[51];
		int count1=0;
		for(int index=0;index<51;index++){
			while (true) {
				int i = random.nextInt(54);
				for(int j =0;j<delete.length;j++){
					if(i != delete[j]){
						delete[count1] = i;
						count1++;
						
					}else{
						break ;
					}
				}
				break;
			}
		}
		ArrayUtil.printArray(delete);
		
		
		
	}
	
	
	
	@Test
	public void testName() throws Exception {
		int random = (int)(Math.random()*100);
		System.err.println(random);
	}

}
